<template>
  <div class="top">
    <p>这个是Right组件内容</p>
    <p>Right组件X坐标:{{ left }} px</p>
    <p>Right组件Y坐标:{{ right }} px</p>
  </div>
</template>

<script>
export default {
  name: "Right",
  setup() {
    let left = ref(0);
    let right = ref(0);

    function movePoint(e) {
      this.left = e.pageX;
      this.right = e.pageY;
    }
    return {
      left,
      right,
      movePoint,
    };
  },
  methods: {},

  mounted() {
    // 添加事件监听
    document.body.addEventListener("click", this.movePoint);
  },
  unBeforeMount() {
    // 组件销毁之前清除事件监听
    document.body.removeEventListener("click", this.movePoint);
  },
};
</script>

<style>
.top {
  background-color: cyan;
  width: 400px;
  height: 400px;
}
</style>